package com.kfpanda.file.monitor;

import javax.annotation.Resource;

import net.contentobjects.jnotify.JNotify;
import net.contentobjects.jnotify.JNotifyListener;

import org.springframework.stereotype.Repository;

@Repository
public class FileMonitor {
	
	@Resource(name="mongodbListener")
	private JNotifyListener listener;

	public void monitor(String path) throws Exception {
		// watch mask, specify events you care about,
		// or JNotify.FILE_ANY for all events.
		int mask = JNotify.FILE_CREATED | JNotify.FILE_DELETED
				| JNotify.FILE_MODIFIED | JNotify.FILE_RENAMED;

		// watch subtree?
		boolean watchSubtree = true;

		// add actual watch
		int watchID = JNotify
				.addWatch(path, mask, watchSubtree, listener);

		// sleep a little, the application will exit if you
		// don't (watching is asynchronous), depending on your
		// application, this may not be required
/*		Thread.sleep(1000000);

		// to remove watch the watch
		boolean res = JNotify.removeWatch(watchID);
		if (!res) {
			// invalid watch ID specified.
		}*/
	}
	
	public static void main(String[] args) throws Exception {
		FileMonitor spl = new FileMonitor();
		spl.monitor("D:\\TDDOWNLOAD");
	}
}
